package edu.stu.book.book.keeping.utils

import java.text.SimpleDateFormat
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.TextStyle
import java.util.Date
import java.util.Locale

object TimeUtils {

    const val YYYY = "yyyy"

    const val MM = "MM"

    const val DD = "dd"

    const val YYYY_MM_DD = "yyyy-MM-dd"

    const val YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"

    const val MM_DD_TEXT = "MM月dd日"

    private val format_HH_mm = SimpleDateFormat("HH:mm", Locale.CHINA)

    private val format_MM_dd = SimpleDateFormat("MM-dd", Locale.CHINA)

    private val format_MM_dd_HH_mm = SimpleDateFormat("MM-dd HH:mm", Locale.CHINA)

    fun getCurrentYear(): Int = LocalDateTime.now().year

    fun getCurrentMonth(): Int = LocalDateTime.now().monthValue

    fun getCurrentDay(): Int = LocalDateTime.now().dayOfMonth

    fun getCurrentHour(): Int = LocalDateTime.now().hour

    fun getCurrentMinute(): Int = LocalDateTime.now().minute

    fun formatTime(format: String, time: Long = Date().time): String {
        return SimpleDateFormat(format, Locale.CHINA).format(Date(time))
    }

    fun getDayOfWeek(year: Int, month: Int, day: Int): String {
        val date = LocalDate.of(year, month, day)
        return date.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA)
    }

    fun getCurrentDayOfWeek(): String {
        val currentDate = LocalDate.now()
        return currentDate.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA)
    }

    fun getCurrentDateTime(): Map<String, Int> {
        val currentDateTime = LocalDateTime.now()
        return mapOf(
            "year" to currentDateTime.year,
            "month" to currentDateTime.monthValue,
            "day" to currentDateTime.dayOfMonth,
            "hour" to currentDateTime.hour,
            "minute" to currentDateTime.minute
        )
    }
}